<?php
declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/11
 * Time: 15:01
 */

namespace App\Model;

use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\SoftDeletes;

class Act extends Model
{
    use SoftDeletes;

    protected ?string $table='act';
    public bool $timestamps = true;


    protected array $fillable = [
        'party_id','type','title','photo','banner','content','start_time','end_time',
        'max_limit','collect_option','status','admin_id'
    ];


    public function party(): \Hyperf\Database\Model\Relations\belongsTo
    {
        return $this->belongsTo(Party::class, 'party_id', 'id');
    }

    public function actPush(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActPush::class, 'act_id', 'id');
    }

    public function joinStatus(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActJoin::class, 'act_id', 'id');
    }

    public function answerJoinStatus(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActAnswerJoin::class, 'act_id', 'id');
    }

    public function answerRule(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActAnswerRule::class, 'act_id', 'id');
    }



    public function prizeJoinStatus(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActPrizeJoin::class, 'act_id', 'id');
    }
    public function prizeRule(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActPrizeRule::class, 'act_id', 'id');
    }
    public function prizeGoods(): \Hyperf\Database\Model\Relations\hasMany
    {
        return $this->hasMany(ActPrizeGoods::class, 'act_id', 'id');
    }


    public function surveyRule(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActSurveyRule::class, 'act_id', 'id');
    }


    public function voteRule(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(ActVoteRule::class, 'act_id', 'id');
    }


    //手机信息
    public function setCollectOptionAttribute($value): void
    {
        $this->attributes['collect_option'] = implode('|', $value);
    }

    public function getCollectOptionAttribute($value): array
    {
        return $value != null ? explode('|', $value) : [];
    }


    public function getContentAttribute($value): string
    {
        return $value != null ? htmlspecialchars_decode($value) : '';
    }

    public function setContentAttribute($value): void
    {
        if($value!='') htmlspecialchars($value);
        $this->attributes['content'] = $value;
    }

}